import { convertHtmlToDocxBuffer } from '../src/index';

// 测试中划线功能
const testStrikethrough = async () => {
  const html = `
    <h1 style="color: #2E86C1; font-family: 'Arial'; font-size: 24pt;">中划线功能测试</h1>
    
    <h2 style="color: #27AE60;">1. 基本中划线</h2>
    <p style="text-decoration: line-through;">这是基本的中划线文字</p>
    
    <h2 style="color: #27AE60;">2. 带颜色的中划线</h2>
    <p style="text-decoration: line-through; color: red;">红色中划线文字</p>
    <p style="text-decoration: line-through; color: blue;">蓝色中划线文字</p>
    
    <h2 style="color: #27AE60;">3. 组合样式</h2>
    <p style="text-decoration: line-through; font-weight: bold;">粗体中划线文字</p>
    <p style="text-decoration: line-through; font-style: italic;">斜体中划线文字</p>
    <p style="text-decoration: line-through; font-weight: bold; color: purple;">紫色粗体中划线文字</p>
    
    <h2 style="color: #27AE60;">4. 部分文字中划线</h2>
    <p>这是正常文字，<span style="text-decoration: line-through;">这部分是中划线</span>，这是正常文字。</p>
    
    <h2 style="color: #27AE60;">5. 下划线+中划线组合</h2>
    <p style="text-decoration: underline line-through;">下划线+中划线文字</p>
    
    <h2 style="color: #27AE60;">6. 在列表中使用</h2>
    <ul>
      <li style="text-decoration: line-through;">中划线列表项</li>
      <li>正常列表项</li>
      <li style="text-decoration: line-through; color: red;">红色中划线列表项</li>
    </ul>
    
    <h2 style="color: #27AE60;">7. 在表格中使用</h2>
    <table border="1">
      <tr>
        <th>产品</th>
        <th>价格</th>
        <th>状态</th>
      </tr>
      <tr>
        <td style="text-decoration: line-through;">已下架产品</td>
        <td style="text-decoration: line-through;">¥999</td>
        <td style="color: red;">已下架</td>
      </tr>
      <tr>
        <td>正常产品</td>
        <td>¥1999</td>
        <td style="color: green;">有货</td>
      </tr>
    </table>
    
    <h2 style="color: #27AE60;">8. 在链接中使用</h2>
    <p><a href="https://example.com" style="text-decoration: line-through;">中划线链接</a></p>
    
    <h2 style="color: #27AE60;">9. 字符间距缩放+中划线</h2>
    <p style="text-decoration: line-through;">
      正常间距中划线 <span data-scale="80" style="text-decoration: line-through;">80%间距中划线</span> 正常间距中划线
    </p>
  `;

  try {
    const result = await convertHtmlToDocxBuffer(html);

    // 创建下载链接
    const blob = new Blob([result.buffer], {
      type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
    });
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'strikethrough-test.docx';
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    window.URL.revokeObjectURL(url);

    console.log('中划线测试完成，文件已下载');
    console.log('警告信息:', result.warnings);
  } catch (error) {
    console.error('中划线测试失败:', error);
  }
};

// 如果是在浏览器环境中，添加到全局对象
if (typeof window !== 'undefined') {
  (window as any).testStrikethrough = testStrikethrough;
}

export { testStrikethrough };
